const api = require("../../utils/cloudAPIUtils");
const utils = require("../../utils/utils");
const app = getApp();

Page({
    data: {
        title:app.globalData.title,
        version:app.globalData.version,
        BXSCHShop:app.globalData.BXSCHShop,
        CommonlyUsed:app.globalData.CommonlyUsed,
        hasMarket:app.globalData.HasMarket
    },
    toGame(){
        const info = app.globalData.gameInfo;
        wx.navigateToMiniProgram({
            appId:info.appId,
            path:info.path,
            envVersion:info.envVersion
        })
    },
    toPage(e){
        const {page,id} = e.currentTarget.dataset;
        if(!page){
            wx.showToast({
              title: '功能开发中...',
              icon:'error'
            })
            return
        }
        if(id){
            wx.reLaunch({url:page})
        }else{
            wx.navigateTo({url:page})
        }
    },

    toLeague:function(params) {
        wx.navigateTo({
          url: '/pages/league/league'
        })
    },

    toDeviceList:function(params) {
        wx.navigateTo({
            url: '/pages/device/list'
          })
    },

    onLoad(options) {
        //登录逻辑
        if (!app.globalData.userInfo.loginToken) {
            wx.showLoading({
                title: '加载中...',
                mask: true
            })
            api.login((res) => {
                wx.hideLoading()
            }, (res) => {
                wx.hideLoading()
                wx.showModal({
                    title: '温馨提示',
                    content: '登录失败',
                    showCancel: false
                })
            })
        }
    },
})